﻿
@{
    ViewBag.Title = "我的货单";
    Layout = "~/Views/Shared/_LayoutEasyUI.cshtml";
}

<table id="grid-list"> </table>

<div id="win" class="easyui-window" title="录入运单号" style="width:600px;height:400px"
     data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,closed:true">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="padding: 120px;">
            <input id="transpNo" class="easyui-textbox" data-options="prompt:'请输入物流单号'" style="width: 300px;">
        </div>
        <div data-options="region:'south',border:false" style="text-align:right;padding:10px;">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="saveTranspBillNo()" style="width:80px">提交</a>

        </div>
    </div>
</div>

@section scripts{
    <script>
        var CurrentOrderId = 0;
        $(function () {
            Grid.LoadData();

        });

        var Grid = {
            LoadData: function () {
                var url = "/Order/DealData";
                Grid.list = $("#grid-list").datagrid({
                    url: url,
                    title: '我的货单',
                    fit: true,
                    fitColumns: true,
                    singleSelect: true,
                    rownumbers: true,
                    nowrap: false,
                    striped: true, //隔行变色
                    //toolbar: [
                    //{
                    //    iconCls: 'icon-edit',
                    //    text: '录入运单号',
                    //    handler: function () {

                    //        var row = Grid.list.datagrid('getSelected');
                    //        if (row) {
                    //            if (row.Status == 2) {
                    //                CurrentOrderId = row.FOrderId;
                    //                $('#win').window('open');
                    //            } else {
                    //                alert('您选中的记录不需要录入物流编号');
                    //            }

                    //        } else {
                    //            alert('请先选择订单！');
                    //        }
                    //    }
                    //}],
                    columns: [[
                        { field: 'ck', checkbox: true, align: 'left', width: 50 },
                        { field: 'FOrderNo', title: '订单编号', width: 100, align: 'center' },
                        {
                            field: 'Status', title: '订单状态', width: 100, align: 'center', formatter: function (value, row, index) {
                                switch (value) {
                                    case 0:
                                        return "已审核";
                                    case 1:
                                        return "已分配";
                                    case 2:
                                        return "已确认";
                                    case 3:
                                        return "已发货";
                                    case 4:
                                        return "已签收";
                                    default:
                                        return "--";
                                }
                            }
                        },
                        {
                            field: 'FTranspBillNo', title: '物流单号', width: 100, align: 'center', formatter: function (value, row, index) {
                                if (row.Status == 2) {
                                    return '<a href="#" onclick="showWindow(' + row.FOrderId + ')">录入运单号</a>';
                                } else if (row.Status == 3) {
                                    return value;
                                } else {
                                    return '';
                                }
                            }
                        },
                        { field: 'FStoreName', title: '门店', width: 100, align: 'center' },
                        { field: 'FVipName', title: '会员名称', width: 100, align: 'center' },
                        { field: 'FShrName', title: '姓名', width: 100, align: 'center' },
                        { field: 'FShrTel', title: '电话', width: 100, align: 'center' },
                        { field: 'FAddress', title: '联系地址', width: 100, align: 'center' },
                        { field: 'FItemName', title: '产品名称', width: 100, align: 'center' },
                        { field: 'FGgModel', title: '规格型号', width: 100, align: 'center' },
                        { field: 'FQty', title: '数量', width: 100, align: 'center' },
                        { field: 'FWeight', title: '重量', width: 100, align: 'center' },
                        { field: 'FVolume', title: '体积', width: 100, align: 'center' },
                        { field: 'FBjPrice', title: '保价金额', width: 100, align: 'center' },
                        { field: 'FDt', title: '有无电梯', width: 100, align: 'center' }

                    ]]
                });
            },
            Refresh: function () {
                Grid.list.datagrid('reload');
            }
        }

        function showWindow(orderid) {
            CurrentOrderId = orderid;
            $('#win').window('open');
        }
        function saveTranspBillNo() {
            var transpNo = $('#transpNo').textbox('getValue');
            if (transpNo.length === 0 || CurrentOrderId === 0) {
                alert("请输入物流单号再提交！");
                return;
            }
            $.ajax({
                url: '/Order/SubmitTranspNo',
                data: {
                    orderid: CurrentOrderId,
                    tspNo: transpNo
                },
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    if (data.success) {
                        Grid.Refresh();
                        $('#win').window('close');
                    } else {
                        alert(data.msg);
                    }
                }
            });
        }
    </script>
}